package com.spx.kernel.types;

import java.lang.reflect.Constructor;

import org.springframework.beans.BeanUtils;

public class ModelUtil
{

	@SuppressWarnings("unchecked")
	public static <T extends ModelType> T duplicate(T subject)
	{
		T result = null;
		try
		{
			final Constructor<T> c = (Constructor<T>) subject.getClass().getConstructor();
			result = c.newInstance();
			BeanUtils.copyProperties(subject, result, new String[] { "id" });

		} catch (final Throwable e)
		{
			throw new RuntimeException(e);
		}

		return result;

	}
}
